home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / XCMD libraries 960603 / xcmdStrings.h < prev    next >
Text File  |  1996-05-29  |  4KB  |  103 lines

  1. //    © Paul B. Beeken, Work In Progress, 1994-5
  2. //    Knowledge Software Consulting.
  3. //
  4. //    These files are a mindlessly simple wrapper class for the
  5. //    basic XCMD operations.  Only one instance of the xcmdBase class is
  6. //    generated per XCMD call but there may be many instances of the XCMDString
  7. //    class.  I have used these classes to whip out XCMD/XFCNs within hours of
  8. //    receiving the specs.  They work great for me but I will always consider 
  9. //    suggestions.
  10. //
  11. //    Please, please, please, in the unlikely event you should use this stuff
  12. //    for some commercial application I would appreciate you contacting me.  If
  13. //    its for your own use, use away. Send email: knowsoft@ios.com
  14. //
  15. //    As always: this file is presented as is with no warrantees expressed or implied.
  16. //    Swim at your own risk, etc. etc.
  17.  
  18. #pragma    once
  19. #include    "xcmdBase.h"
  20.  
  21. #ifndef    __HYPERXCMD__
  22. #include    <HyperXCmd.h>
  23. #endif
  24.  
  25. //
  26. //    Strings form a very important basis for information exchange in
  27. //    hypercard's xcmds and xfcns.  It predates the abstract object hierarchy
  28. //    devised for AppleScript.  All information is passed using handles to 
  29. //    null terminated strings.  Hypercard is a bit schitzophrenic (as is my spelling)
  30. //  though. Many
  31. //    of the call back functions require the use of pascal type strings.  The 
  32. //    creation of a special class to handle these objects is an attempt to deal
  33. //    with this problem in a transparent way.
  34. //
  35. //    N.B. an xcmd base object must be instantiated before any of the member
  36. //    functions are called.  The xcmdBase object sets up the paramPtr which
  37. //    is the vector for the call backs.
  38. //
  39.  
  40. class    xcmdString    {
  41.  
  42.     friend    class    xcmdBase;            // has to be our friend for it to set up out paramPtr
  43.  
  44.     private:
  45.         static    XCmdPtr        paramPtr;    // allocated when xcmdBase object is instantiated.
  46.  
  47.         short    len;                    // string length
  48.         char*    str;                    // storage for the string.
  49.  
  50.             //    Bottlenecks for string conversion
  51.         StringPtr    pStr( void ) const    { return StringPtr(str); };    
  52.         char*        cStr( void ) const    { return &str[1]; }
  53.  
  54.     public:
  55.     
  56.         xcmdString();                                        // empty pointer
  57.         xcmdString( Handle s, Boolean useHandLen=false );    // most common type.
  58.         ~xcmdString();
  59.         
  60.         // sometimes we need the string explicitly.
  61.         int        length( void )    const;
  62.         
  63.         // constructors operators for useful types:
  64.         xcmdString( xcmdString& s );    // copy constructor
  65.         xcmdString( char* s );
  66.         xcmdString( char* s, long n );
  67.         xcmdString( StringPtr s );
  68.         xcmdString( Boolean v );
  69.         xcmdString( double_t v );
  70.         xcmdString( unsigned long v );
  71.         xcmdString( long v, short nd );
  72.         xcmdString( long v );
  73.         xcmdString( Point pt );
  74.         xcmdString( Rect& rct );
  75.         
  76.         // conditioners
  77.         void    trimWhiteSpace( void );                // trims any leading or trailing space.
  78.         // coersion operators for useful types:
  79.         operator Boolean() const;                 // coerece to a Boolean (string is true or false)
  80.         operator Rect() const;                    // coerce to a Rect structure
  81.         operator Point() const;                    // coerce to a Point
  82.         operator long() const;                    // coerce to a signed long value
  83.         operator unsigned long() const;            // coerce to an unsigned long value
  84.         operator double_t() const;                // coerce to an extended value
  85.         operator StringPtr() const;                // coerce to a pascal string ptr
  86.         operator char*() const;                    // coerce to a c string ptr
  87.         operator Handle() const;                // coerce to a Handle. n.b. user must dispose if not returned to hc.
  88.     
  89.         
  90.         // some important operators
  91.         long        contains( const xcmdString& s2 ) const;        // offset of s2 in me (1 based)
  92.  
  93.         xcmdString&    operator=( const xcmdString& s2 );    // assignment
  94.         xcmdString&    operator&=( const xcmdString& s2 );    // append assignment
  95.         char        operator[]( const int i );
  96.         friend
  97.         xcmdString    operator&( const xcmdString& s1, const xcmdString& s2 );        // catenation
  98.         friend
  99.         Boolean     operator==( const xcmdString& s1, const xcmdString& s2 );
  100.         friend
  101.         Boolean        operator!=( const xcmdString& s1, const xcmdString& s2 );
  102.         
  103.     };